<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>


</body>
<script>
  //  <!-- 使用字面量创建 -->
  var obj = {
    name: '小明',
    sex: '男',
    age: 15,
    hello: function () {
      console.log('这是方法')
    }
  }
  // 使用声名对象
  var obj2 = new Object()
  obj2.name = '小红'
  obj2.sex = '女'
  obj2.age = 17
  obj2.hello = function () {
    console.log('aaaaaaaa');
  }

  function Obj(name, sex, age, hello) {
    this.name = name
    this.sex = sex
    this.age = age
    this.hello
  }
  var obj3 = new Obj('小明', '男', 18, function () {
    console.log('小明的方法');
  })
  obj3.add = 'newParam'
  //遍历可枚举属性
  console.log('===========');
  for (const key in obj) {
    console.log(key)
    console.log(typeof key);
    console.log(obj[key])
  }
  console.log('===========');
  //返回对象可枚举属性的数组
  var arr = Object.keys(obj2)
  console.log(arr);
  arr.forEach(function (v, i) {
    console.log(v, i);
  })
  //返回对象所有属性（包括不可枚举）的数组
  arr = Object.getOwnPropertyNames(obj3)
  console.log(arr)
  console.log('add' in obj3);
</script>

</html>